/*
 * HttpServer.h
 *
 *  Created on: 12.06.2011
 *      Author: sili
 */

  // http://mongoose.googlecode.com/svn/trunk/ used svn version 518

#ifndef HTTPSERVER_H_
#define HTTPSERVER_H_

#include "Tools.h"

#include "Controller.h"
#include "TemplateFactory.h"
#include "PropertyFactory.h"
#include "SystemFactory.h"
#include "LogFactory.h"
#include "AALItem.h"
#include "AALLocatorItem.h"
#include "AALSensorItem.h"
#include "AALActorItem.h"
#include "UriCodec.h"

#include "mongoose.h"

#include <sstream>
#include <stdio.h>

//#define MAX_MESSAGE_LEN 255			// the max length in chars a message or data can have
//#define MAX_MESSAGES 50				// max history length (ringbuffer)

class HttpServer : public ActionListener{
private:
	Controller * controller;
	struct mg_context * ctx;
	string uploadDir;
public:
	HttpServer(Controller * _controller, const char * _configDir);
	virtual ~HttpServer();

	/**
	 * OVERWRITE
	 * I'm an ActionListener
	 */
	void doAction(AALAction * _action);
	void doMainSavedAction();

	void visualize(struct mg_connection * _conn,
			const struct mg_request_info * _request_info,
			ActionType _actionType);

	void getAvailableAALItems(struct mg_connection * _conn,
			const struct mg_request_info * _request_info);
	void modifyAALItem(struct mg_connection * _conn,
			const struct mg_request_info * _request_info);
	void deleteAALItem(struct mg_connection * _conn,
			const struct mg_request_info * _request_info);

	void getAvailableTypes(struct mg_connection * _conn,
			const struct mg_request_info * _request_info);

	void uploadSvgFile(struct mg_connection * _conn,
			const struct mg_request_info * _request_info);
	void importSvgFile(struct mg_connection * _conn,
			const struct mg_request_info * _request_info);
	void getUploadedFiles(struct mg_connection * _conn,
			const struct mg_request_info * _request_info);
	void deleteUploadedFile(struct mg_connection * _conn,
			const struct mg_request_info * _request_info);

	void getAvailableTemplates(struct mg_connection * _conn,
			const struct mg_request_info * _request_info);
	void modifyTemplate(struct mg_connection * _conn,
			const struct mg_request_info * _request_info);
	void deleteTemplate(struct mg_connection * _conn,
			const struct mg_request_info * _request_info);
	void getTemplateImages(struct mg_connection * _conn,
			const struct mg_request_info * _request_info);

	void getAvailableProperties(struct mg_connection * _conn,
			const struct mg_request_info * _request_info);
	void modifyProperty(struct mg_connection * _conn,
			const struct mg_request_info * _request_info);
	void deleteProperty(struct mg_connection * _conn,
			const struct mg_request_info * _request_info);
	void getPropertyDefinitions(struct mg_connection * _conn,
		const struct mg_request_info * _request_info);

	void changeValue(struct mg_connection * _conn,
			const struct mg_request_info * _request_info);

	void returnMessages(struct mg_connection * _conn,
			const struct mg_request_info * _request_info);

	void getMessageTypes(struct mg_connection * _conn,
			const struct mg_request_info * _request_info,
			const char * _requestType);

};
#endif /* HTTPSERVER_H_ */
